package com.sun.example.recyclerview;

import android.graphics.Color;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.sun.example.R;

import java.util.List;

/**
 * @author tianxiaolong
 * time：2019-10-04 17:18
 * description：
 */
public class DemoAdapter  extends RecyclerView.Adapter<DemoAdapter.ViewHolder> {

	List<String> list;

	public DemoAdapter(List<String> list) {
		this.list = list;
	}

	private int count = 0;

	{
		setHasStableIds(true);
	}
	@NonNull
	@Override
	public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
		View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_text,parent,false);
		count+=1;

		Log.d("DemoAdapter","count:"+count);
		return new ViewHolder(view);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
		if(position ==0 || (position-DemoActivity.MAX_FIRST_CLOUNMS)%DemoActivity.MAX_CLOUNMS==0){
			holder.itemView.setBackgroundColor(Color.RED);
		}else {
			holder.itemView.setBackgroundColor(0xFF000fff);
		}
		holder.textView.setText(list.get(position));
	}

	@Override
	public int getItemCount() {
		return list.size();
//		return DemoActivity.MAX_FIRST_CLOUNMS+30*DemoActivity.MAX_CLOUNMS;
	}

	static class  ViewHolder extends RecyclerView.ViewHolder{


		public TextView textView;
		public ViewHolder(@NonNull View itemView) {
			super(itemView);
			textView = itemView.findViewById(R.id.item_text);
		}
	}
}
